//
//  QZAuthorTool.m
//  QZ相机和相册
//
//  Created by 蓝科 on 16/4/21.
//  Copyright © 2016年 范庆忠. All rights reserved.
//

#import "QZAuthorTool.h"
#import <UIKit/UIKit.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import <Photos/Photos.h>

@implementation QZAuthorTool

+(void)authorToolAccessCameraSuccess:(BlockType)successBlock fail:(BlockType)failBlock
{
    //判断有没有相机功能
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        AVAuthorizationStatus status=[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
        if (status == AVAuthorizationStatusDenied||status==AVAuthorizationStatusRestricted) {
            failBlock();
        }else
        {
            successBlock();
        }
    }else{
//        NSLog(@"您的设备没有相机功能");
    }
}
+(void)authorToolAccessLibrarySuccess:(BlockType)successBlock fail:(BlockType)failBlock
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        //判断相机权限是否打开
        if ([UIDevice currentDevice].systemVersion.floatValue >=8.0) {
            //获取系统版本8.0以上相册的权限状态
            PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
            if (status==PHAuthorizationStatusDenied||
                status==PHAuthorizationStatusRestricted) {
                //执行失败的block
                failBlock();
            } else {
                //执行成功的block
                successBlock();
            }
            
        } else {
            //获取系统版本4.0-9.0相册的权限状态
            ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
            if (status==ALAuthorizationStatusDenied||
                status==ALAuthorizationStatusRestricted) {
                //执行失败的block
                failBlock();
            } else {
                //执行成功的block
                successBlock();
            }
        }
    } else {
//        NSLog(@"您的设备没有相册");
    }
}
@end
